package com.dts.controller;

import com.dts.dto.UserDto;
import com.dts.entity.User;
import com.dts.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(UserDto user, HttpServletRequest request) {
        User login = userService.login(user);
        if (login != null) {
            request.getSession().setAttribute("user", login);
            return "redirect:/good/list";
        }
        return "/login";
    }

    @RequestMapping("/logout")
    public String logout(HttpServletRequest request) {
        request.getSession().removeAttribute("user");
        return "redirect:/login.jsp";
    }


}
